﻿/*
 * OpenDoPE Word Add-In
 * Copyright (C) 2010-2011  Plutext Pty Ltd
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * 
 * For details, see http://www.gnu.org/licenses/gpl-2.0.html
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OpenDoPE_Wed
{
    public partial class FormResponses : Form
    {
        private responseFixed responseFixed;

        public FormResponses(responseFixed responseFixed)
        {
            InitializeComponent();
            this.responseFixed = responseFixed;

            // Pre-populate with true/false
            this.dataGridView1.Rows.Add(2);
            this.dataGridView1.Rows[0].Cells[0].Value = "true";
            this.dataGridView1.Rows[0].Cells[1].Value = "yes";
            this.dataGridView1.Rows[1].Cells[0].Value = "false";
            this.dataGridView1.Rows[1].Cells[1].Value = "no";
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.Rows.Count < 3) // auto last row
            {
                Mbox.ShowSimpleMsgBoxError("You must provide at least 2 choices!");
                return;
            }

            int last = this.dataGridView1.Rows.Count -1;
            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                // Last row is added automatically
                if (row == this.dataGridView1.Rows[last]) continue;

                DataGridViewCell c = row.Cells[0];
                if (string.IsNullOrWhiteSpace((string)c.Value))
                {
                    Mbox.ShowSimpleMsgBoxError("You must enter data in each cell!");
                    return;
                }
                c = row.Cells[1];
                if (string.IsNullOrWhiteSpace((string)c.Value))
                {
                    Mbox.ShowSimpleMsgBoxError("You must enter data in each cell!");
                    return;
                }
            }

            // OK

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                if (row == this.dataGridView1.Rows[last]) continue;

                responseFixedCategory category = new OpenDoPE_Wed.responseFixedCategory();

                category.value = (string)row.Cells[0].Value;
                category.label = (string)row.Cells[1].Value;

                responseFixed.category.Add(category);
            }

            if (this.radioButtonYes.Checked)
            {
                responseFixed.canSelectMany = true;
            }
            else
            {
                responseFixed.canSelectMany = false;
            }
            responseFixed.canSelectManySpecified = true; // do i need to set this?

            this.Close();

        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Mbox.ShowSimpleMsgBoxError("Not implemented yet!");
        }
    }
}
